home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1998
/
MacHack 1998.toast
/
The Hacks!
/
WackyWindows
/
Sound
/
snd.c
next >
Wrap
C/C++ Source or Header
|
1998-06-19
|
4KB
|
150 lines
// ******************************************************************
// program written by
// Paul Baxter
// MacHack'98
//
//
// ******************************************************************
#include <A4Stuff.h>
#include <stdlib.h>
#include "patch.h"
// #include "debug.h"
// Function Prototypes
pascal void PlaySound(void);
pascal void StopSoundNow(void);
pascal void Sound_CallBack(SndChannelPtr chan, SndCommand *cmd);
// Globals
SndListHandle* gMySounds = nil;
SndChannelPtr gSoundChannel = nil;
short gNumSounds = 0;
short *gSoundIndex = nil;
short gCurSound = 0;
#ifdef powerc
// for Metrowerks' linker, this defines the interface for main().
ProcInfoType __procinfo = SoundInstallerUPPProcInfo;
#endif
pascal PlaySoundUPP main(short numsounds, short* soundindex, SndListHandle* sounds);
// * ******************************************************************************
// * main
// * Entry point for the PlaySound Installer
// * ******************************************************************************
pascal PlaySoundUPP main(short numsounds, short* soundindex, SndListHandle* sounds)
{
SndCallBackUPP snd_callbackptr;
PlaySoundUPP SoundPlayer;
SndCommand mySndcommand;
THz theZone;
short rfile;
OSErr err;
EnterCodeResource();
// DEBUG("Enter SoundInstaller");
gSoundIndex =soundindex;
gMySounds = sounds;
gNumSounds = numsounds;
theZone = GetZone();
SetZone(SystemZone());
SoundPlayer = nil;
srand((unsigned int)TickCount());
rfile = CurResFile();
SoundPlayer = NEW_PLAYSOUNDPROC(PlaySound);
if (SoundPlayer) {
snd_callbackptr = NewSndCallBackProc(Sound_CallBack);
if (snd_callbackptr) {
err = SndNewChannel(&gSoundChannel, 0, 0, snd_callbackptr);
if (!err && gSoundChannel) {
mySndcommand.cmd = quietCmd;
mySndcommand.param2 = 0;
err = SndDoImmediate(gSoundChannel, &mySndcommand);
}
}
}
SetZone(theZone);
// DEBUG("Exit SoundInstaller");
ExitCodeResource();
return SoundPlayer;
}
// * ******************************************************************************
// * PlaySound
// * Function to Play Sounds
// * ******************************************************************************
pascal void PlaySound(void)
{
SndCommand mySndcommand;
Handle theSoundHandle;
OSErr err;
short index;
EnterCodeResource();
if (gSoundChannel && gMySounds && gSoundIndex) {
StopSoundNow();
index = gSoundIndex[gCurSound++];
if (gCurSound >= gNumSounds)
gCurSound = 0;
theSoundHandle = (Handle) gMySounds[index];
if (theSoundHandle) {
err = SndPlay(gSoundChannel, (SndListHandle)theSoundHandle, true);
mySndcommand.cmd = callBackCmd;
mySndcommand.param2 = (long)theSoundHandle;
err = SndDoCommand(gSoundChannel, &mySndcommand, true);
}
}
ExitCodeResource();
}
// * ******************************************************************************
// * Sound_CallBack
// * Sound Call Back Routine
// * ******************************************************************************
pascal void Sound_CallBack(SndChannelPtr chan, SndCommand *cmd)
{
#pragma unused (chan, cmd)
EnterCodeResource();
ExitCodeResource();
}
// * ******************************************************************************
// * StopSoundNow
// * Stop the current sound
// * ******************************************************************************
pascal void StopSoundNow(void)
{
SndCommand mySndcommand;
OSErr err;
EnterCodeResource();
if (gSoundChannel) {
mySndcommand.cmd = quietCmd;
mySndcommand.param2 = 0;
err = SndDoImmediate(gSoundChannel, &mySndcommand);
mySndcommand.cmd = callBackCmd;
mySndcommand.param2 = 0;
err = SndDoImmediate(gSoundChannel, &mySndcommand);
}
ExitCodeResource();
}